package com.zhang.aloneway_springboot.service.impl;

import com.zhang.aloneway_springboot.dao.CategoryDao;
import com.zhang.aloneway_springboot.pojo.Category;
import com.zhang.aloneway_springboot.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.persistence.Id;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public List<Category> doList(){
        //一执行doList方法 就排完序后查询出  种类  的列表
        Sort sort = Sort.by(Sort.Direction.DESC,"id");
        return categoryDao.findAll(sort);
    }

    @Override
    public Category get(Integer id) {
        //通过这个方法获取到category对象
        Category category = categoryDao.findById(id).orElse(null);
        //把这个对象返回给bookServiceImpl中
        return category;
    }
}
